import unittest
from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


class login(unittest.TestCase):
    def setUp(self) -> None:
        driverPath='C:/driver/chromedriver.exe'
        service=Service(driverPath)
        self.br=webdriver.Chrome(service=service)
        self.br.get('https://www.atstudy.com/')
        sleep(2)
        self.br.maximize_window()
        self.br.find_element(By.XPATH,'//*[@id="__layout"]/div/div[1]/div/div[1]/div[3]/div[3]/button[1]').click()
        sleep(2)
        self.br.find_element(By.CSS_SELECTOR,'#__layout > div > div > div > div > div.lg > div > div > div.pic > div:nth-child(2) > img').click()
        sleep(2)
        self.br.find_element(By.XPATH,'//*[@id="__layout"]/div/div/div/div/div[2]/div/div/div[1]/div[1]/div[2]/input').send_keys('18326923357')
        self.br.find_element(By.XPATH,'//*[@id="__layout"]/div/div/div/div/div[2]/div/div/div[1]/div[1]/div[3]/div/input').send_keys('kdd485720')
        self.br.find_element(By.XPATH,'//*[@id="__layout"]/div/div/div/div/div[2]/div/div/div[1]/div[2]/button').click()
        sleep(3)
        # 头像图片
        e1=self.br.find_element(By.CSS_SELECTOR,'#__layout > div > div:nth-child(1) > div > div.top_index > div.t_right > div.login > div > img')
        self.assertTrue(e1,'登录失败')

    def tearDown(self) -> None:
        # 头像图片
        e = self.br.find_element(By.CSS_SELECTOR,'#__layout > div > div:nth-child(1) > div > div.top_index > div.t_right > div.login > div > img')
        ActionChains(self.br).move_to_element(e).perform()
        self.br.find_element(By.CSS_SELECTOR,'#__layout > div > div:nth-child(1) > div > div.top_index > div.t_right > div.login > div > div > div > div:nth-child(3) > p').click()
        sleep(2)
        e1 = self.br.find_element(By.CSS_SELECTOR, '#__layout > div > div:nth-child(1) > div > div.top_index > div.t_right > div.login > button:nth-child(2)')
        self.assertTrue(e1, '退出失败')
        self.br.quit()


if __name__ == '__main__':
    unittest.main()
    # ts=unittest.TestSuite()
    # T


